2
2
.
.
5
5
.
.
1
1
P
P
r
r
o
o
p
p
e
e
r
r
t
t
i
i
e
e
s
s
-
-
P
P
u
u
b
b
l
l
i
i
c
c
I
I
n
n
f
f
o
o
[
[
G
G
]
]
This tutorial shows how to create Entity that only has public Properties.
This way Entity is made very simple since there is no need for getters and setters.
Instead we can directly access Properties when we want to read them or set their values.
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @RequestMapping. Includes Tomcat Server.
PersonEntity
http://localhost:8080/Hello
Tomcat
Browser
MyController
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: entity_application (add Spring Boot Starters from the table)
Create Package: entities (inside main package)
– Create Class: PersonEntity.java (inside package entities)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside package controllers)
PersonEntity.java
package com.ivoronline.entity_application.entities;
public class PersonEntity {
public Long id;
public String name;
public Integer age;
}
MyController.java
package com.ivoronline.entity_application.controllers;
import com.ivoronline.entity_application.entities.PersonEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController {
PersonEntity personEntity = new PersonEntity();
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
personEntity.name = "John";
String name = personEntity.name;
return "Hello " + name;
}
}
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8080/Hello
Application Structure
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>